package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.dto.OrderDTO;
import com.itheima.service.OrderService;
import com.itheima.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 体检预约
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 体检预约
     * @param orderDTO
     * @return
     */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody OrderDTO orderDTO){
        log.info("体检预约,{}", orderDTO);
        try {
            Result result = orderService.submitOrder(orderDTO);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "未知错误，请联系管理员", null);
        }
    }

    @PostMapping("/findById")
    public Result findById(Integer id){
        log.info("根据预约id查询预约信息，{}", id);
        try {
            OrderVO orderVO = orderService.findById(id);
            return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS, orderVO);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_ORDER_FAIL, null);
        }
    }
}
